<template>
	<view class="register">

		<view class="content">
			<!-- 头部logo -->
			<view class="header">
				<image src="../../static/img/logo.png"></image>
			</view>
			<!-- 主体 -->
			<view class="main">
				<wInput v-model="username" type="text" maxlength="11" placeholder="用户名"></wInput>
				<wInput v-model="nickname" type="text" maxlength="11" placeholder="用户昵称"></wInput>
				<wInput v-model="password" type="password" maxlength="11" placeholder="登录密码" isShowPass></wInput>
			</view>
			<wButton class="wbutton" text="注 册" :rotate="isRotate" @tap="startReg()" bgColor="var(--echo-main-color)"></wButton>
			<!-- 底部信息 -->
			<view class="footer">
				<u-checkbox-group placement="row" @change="agree">
					<u-checkbox v-model="checked" name="同意" size="14"></u-checkbox>同意
				</u-checkbox-group>
				<!-- 协议地址 -->
				<navigator url="" open-type="navigate" class="agreement">《火源社区协议》</navigator>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		register
	} from '@/config/api.js';
	import wInput from '../../components/watch-login/watch-input.vue' //input
	import wButton from '../../components/watch-login/watch-button.vue' //button

	export default {
		data() {
			return {
				checked: false,
				username: '', // 用户名
				password: '', // 密码
				nickname: '', // 用户昵称 双向绑定
				isRotate: false, //是否加载旋转
			}
		},
		components: {
			wInput,
			wButton,
		},
		methods: {
			agree() {
				this.checked = !this.checked
			},
			startReg() {
				//注册
				if (this.isRotate) {
					//判断是否加载中，避免重复点击请求
					return false;
				}
				if (this.checked == false) {
					uni.showToast({
						icon: 'none',
						position: 'bottom',
						title: '请先同意《协议》'
					});
					return false;
				}
				register({
					username: this.username,
					password: this.password,
					nickname: this.nickname
				}).then(res => {
					if (res)
					uni.showToast({
						icon: 'success',
						position: 'bottom',
						title: '注册成功'
					});
					setTimeout(()=>{
						uni.navigateTo({
							url: "/pages/login/login"
						})
					},2000)
				})
			}
		}
	}
</script>

<style>
	@import url("./css/main.css");
</style>
